package com.wuzy.core.controller;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wuzy.core.pojo.ResultMessage;
import com.wuzy.core.pojo.SysUser;
import com.wuzy.core.service.ISysUserService;

@Controller
@RequestMapping("/admin/")
public class SysUserLoginController {
	@Autowired
	private ISysUserService sysUserService;
	@ResponseBody
	@RequestMapping("loginCheck")
	public ResultMessage loginCheck(HttpServletRequest request,
			@RequestParam( "account" ) String account,
			@RequestParam( "password" ) String password){
		SysUser sysUser=sysUserService.selectByAccount(account);
		ResultMessage rm=new ResultMessage();
		if(null==sysUser){
			rm.setStatus(0);
			rm.setMessage("该账户不存在！");
			return rm;
		}else if(sysUser.getPassword().equals(password)){
			rm.setStatus(1);
			rm.setMessage("恭喜您，登录成功！");
			request.getSession().setAttribute("sysUser", sysUser);
			return rm;
		}else{
			rm.setStatus(0);
			rm.setMessage("密码错误，请重新输入！");
			return rm;
		}
	}
	@RequestMapping("login")
	public ModelAndView login(){
		return new ModelAndView("login");
	}
	@RequestMapping("index")
	public ModelAndView index(HttpServletRequest request){
		
		return new ModelAndView("index");
	}
}
